package com.loveprogrammer.service.impl;

import com.loveprogrammer.dao.UserRepository;
import com.loveprogrammer.domain.User;
import com.loveprogrammer.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Optional;

/**
 * @ClassName UserServiceImpl
 * @Description 用户服务实现类
 * @Author admin
 * @Date 2024/2/6 17:14
 * @Version 1.0
 */
@Service
public class UserServiceImpl implements IUserService {

    @Autowired
    private UserRepository userRepository;

    @Override
    public List<User> getUserList() {
        return userRepository.findAll();
    }

    @Override
    public User findUserById(Integer id) {
        Optional<User> user = userRepository.findById(id);
        return user.orElse(null);
    }

    @Override
    public User findUserByNickname(String name) {

        return userRepository.findByNickName(name);
    }

    @Override
    public User findUserByAccount(String account) {
        return userRepository.findByAccount(account);
    }

    @Override
    public void save(User user) {
        userRepository.save(user);
    }

    @Override
    public void edit(User user) {
        userRepository.save(user);
    }

    @Override
    public void delete(Integer id) {
        userRepository.deleteById(id);
    }
}
